 var str="";
   str= getvl("chanshu");
   var strs=str.split(",");
   
 var userid=getvl("id");
 $(function(){
 	weihuofabu(str);
 });
 
 
function weihuofabu(str){
	  	$("#tuijianci").html("");
    	$("#fabuweihuo").html("");
    	
    	 $.ajax({
      url: urlcore + "/api/goods/selectgoodsAllag?str="+str,
			type: "get",
			dataType: 'json',
			contentType: "application/json;charset=utf-8",
			success: function(data) {
				if(data.success == true) {
					var sun=1;
					//alert(JSON.stringify(data.data));
					var zuidacishu=parseInt($("#zuidacishu").html());
					if(zuidacishu>=data.data.length){
						var haineng=zuidacishu-data.data.length;
						$("#tuijianci").append("(还能推荐"+haineng+"款商品)");
					}else{
						 if(data.data.length>zuidacishu){
						 	var chao=data.data.length-zuidacishu;
						   	$("#tuijianci").append("(已超出"+chao+"款推荐商品)");
						 }
						
					}
					$.each(data.data, function(y,n) {
				var fabuweihuo='<div class="clearfix add_goods">'+
'		<div class="public-xuanze fl" >'+
'			<img src="../images/delete.png" onclick="removeByValues('+n.id+')" width="20" height="20" />'+
'		</div>'+
'		<div class="clearfix tuwen">'+
'	    	<a href="javascript:void(0);">'+
'		        <div class="tuwen-img fl">'+
'		            <img src="'+n.coverUrl+'" width="75" height="75">'+
'		        </div>'+
'		        <div class="tuwen-wenzi">'+
'		            <h5 class="wuye_h01">'+n.goodsTitle+'</h5>'+
'		            <div class="wuye_div02">&yen;'+n.tradePrice+'-&yen;'+n.getPrice+'</div>'+
'		        </div>'+
'	        </a>'+
'	    </div>'+
'	</div>';
                 $("#fabuweihuo").append(fabuweihuo);
					});
				} else if(data.code == 'OVERTIME') {
					var thisUrl = window.location.href;
					alert(thisUrl);
					if(thisUrl.indexOf('1.0.0denglu.html') <= -1) {
						top.window.location.href = "1.0.0denglu.html";
					}
				} else {
					if(data.msg != '空数据') {
						alert(data.msg)
					} else {
						$('#thiscount').text(0);
					}
				}
			},
			error: function() {
				alert("error");
			}
		});	
}

 //提交
   function baochun(){
   	if(uuuuid!=''){
   		
   			var sts=strs.toString();
   			/*var im=sts.split(",");*/
   			
   			var demo08=$("#demo088").html();
   			//alert(demo08);
   			var demo09=$("#demo099").html();
   			if(demo08=="请选择"){
   				alert("请选择开始时间");
   			}else if(demo09=="请选择"){
   				alert("请选择结束时间");
   			}else {
   		    var starttime="1997-10-24"+demo08+"00"; //开始时间
   			var endtime="1997-10-24"+demo09+"00"; //结束时间
   				if(starttime>=endtime){
   					   alert("开始时间<结束时间");
   				}else{
             $.ajax({
		url: urlcore + "/api/autoRecommend/addAutoRecommend",
		type: "post",
		contentType: "application/json;charset=utf-8",
		data:JSON.stringify({
			goodsIds:sts,
			startTime:demo08,
			endTime:demo09
		}),
		dataType: "json",
		success: function(data) {
			if(data.success == true) {
				alert("添加成功！");
		window.location.href ="20.4.0zidongtuijian.html";
		     }
		},error: function() {
			alert("error");
		}
	    });
   	      }
   			}
   			/*var kuchun=$("#kuchun").val();
   			var shihuijia=$("#shihuijia").val();*/
   	}else{
   		alert("异常");
   	}
   	
   }
   
   
   



//删除数组元素
function removeByValues(val) {
	//alert(val);
  removeByValue(strs,val);
    strs.toString();
 //alert(strs.toString())
  weihuofabu(strs);
}

dongtuijian();
function dongtuijian(){
       $("#zidongtuijian").html("");
    	 $.ajax({
      url: urlcore + "/api/autoRecommend/getMyRecommendTime",
			type: "get",
			dataType: 'json',
			contentType: "application/json;charset=utf-8",
			success: function(data) {
				if(data.success == true) {
					
		var tuijain='<p>您拥有<em id="zuidacishu">'+data.data.autoRecommendAllLimit+'</em>次推荐次数，最多可以选择<em>'+data.data.autoRecommendAllLimit+'</em>个商品在规定的<em>推荐时间段</em>内进行自动推荐</p>';
		$("#zidongtuijian").html(tuijain);
					
					
				} else if(data.code == 'OVERTIME') {
					var thisUrl = window.location.href;
					alert(thisUrl);
					if(thisUrl.indexOf('1.0.0denglu.html') <= -1) {
						top.window.location.href = "1.0.0denglu.html";
					}
				} else {
					if(data.msg != '空数据') {
						alert(data.msg)
					} else {
						$('#thiscount').text(0);
					}
				}
			},
			error: function() {
				alert("error");
			}
		});	

	
}












